package com.bay1ts.controller;

import javax.annotation.Resource;

import com.bay1ts.domain.Users;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

@Controller
@SessionAttributes("user")
public class BaseController {
	@Resource(name="sessionRegistry")
	private SessionRegistry SessionRegistry;
	@RequestMapping("/")
	public String index(){
		return "index";
	}

	@RequestMapping("/about")
	public String about(){
		return "about";
	}
	@RequestMapping("/login")
	public void login(){
		
	}
	@RequestMapping("signup")
	public String showsignuppage(){
		return "signup";
	}
	@RequestMapping(value="signup",method=RequestMethod.POST)
	public String signup(){
		return "redirect:insert";
	}
	@RequestMapping("insertsuccess")
	public String insertSuccess(@ModelAttribute("user") Users user, Model model){
		return "insertSuccess";
	}
	@ModelAttribute("numUsers")
	public int getNumberOfCurrentUsers(){
		return SessionRegistry.getAllPrincipals().size();
	}
	/**
	 * @author bay1ts
	 * @email bay1ts@gmail.com
	 * 这个页面用ajax传递数据，先去数据库查询一下有没有这个用户，没有的话报警，有的话提交
	 */
	@RequestMapping(value="forgot")
	public String showforgotpwpage(){
		return "forgot";
	}
	
	
}
